package com.meihua.shellapp.adapter.personalcenter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.meihua.shellapp.R;
import com.meihua.shellapp.databean.SupplierDataBean;

import java.util.List;

/**
 * 作者：lc on 2017/10/17.
 * 邮箱：lc0607live@163.com
 */

public class TypeAdapter extends BaseAdapter {

    private Context context;
    private List<String> data;
    private int index = -1;

    public int getIndex() {
        return index;
    }

    public TypeAdapter(Context context, List<String> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        view = LayoutInflater.from(context).inflate(R.layout.item_supplier, null);
        final TextView tv_name = view.findViewById(R.id.tv_name);
        tv_name.setText(data.get(i));
        if (i == index) {
            tv_name.setBackgroundResource(R.color.colorAppTitleBg);
            tv_name.setTextColor(context.getResources().getColor(R.color.white));
        } else {
            tv_name.setBackgroundResource(R.color.color_parting);
            tv_name.setTextColor(context.getResources().getColor(R.color.color_font_26px));
        }
        tv_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                index = i;
                notifyDataSetChanged();
            }
        });
        return view;
    }
}
